/**
 * Created by litao on 2018/10/8.
 */
import JBoot from 'jboot-env';
import 'jboot-env/style/number-font/index.css';
// import JBoot from '../../jboot-env/index';

import Vue from 'vue';

import './style/index.scss';

import configure from './configure/index';
let T = new JBoot(Vue, configure);

T.$vue.prototype.$formatMoney = formatMoney;

T.$vue.prototype.$formatExportJson=function(filterVal, jsonData) {
    return jsonData.map(v => filterVal.map(j => {

        let keys = (j.split('.') || []).filter(item => item),
            obj = Object.assign({}, v);

        for (let i = 0; i < keys.length; i++) {
            obj = obj[keys[i]];
        }
        return obj;
    }))
};

Vue.filter('money', formatMoney);

function formatMoney(val) {
    val=val/100;
    val = val.toString().replace(/\$|\,/g,'');
    if(isNaN(val)) {
        val = "0";
    }
    let sign = (val == (val = Math.abs(val)));
    val = Math.floor(val*100+0.50000000001);
    let cents = val%100;
    val = Math.floor(val/100).toString();
    if(cents<10) {
        cents = "0" + cents
    }
    for (var i = 0; i < Math.floor((val.length-(1+i))/3); i++) {
        val = val.substring(0,val.length-(4*i+3))+',' + val.substring(val.length-(4*i+3));
    }

    return (((sign)?'':'-') + val + '.' + cents);
}
